package cn.zwx.learn.spring.orm.core.utils;


import org.apache.commons.beanutils.Converter;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class LocalDataConverter implements Converter {
    @Override
    public <T> T convert(Class<T> aClass, Object obj) {
        if (null == obj){
            return null;
        }
        if (aClass == Date.class){
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = (LocalDateTime) obj;
            ZonedDateTime zdt = localDateTime.atZone(zoneId);
            return (T) Date.from(zdt.toInstant());

        }
        return (T) obj;
    }
}
